package ui;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;


import controller.MobilePlanSellAndBillSystem;
import customexceptions.LineAlreadyExistsException;
import customexceptions.LineNotExistsException;
import customexceptions.PlanNotExistsException;
import customexceptions.UserNotExistsException;



/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class CreateAdditionalLineUI extends javax.swing.JFrame {
	private JTextField jTextFieldTitularLineNumber;
	private JLabel jLabelTitularLineNumber;
	private JTextField jTextFieldAdditionalLineNumber;
	private JLabel jLabelAdditionalLineNumber;
	private JTextField jTextFieldPlanNumber;
	private JLabel jLabelPlanNumber;
	private JLabel  jLabelAdditionalName;
	private JTextField jTextFieldAdditionalName;
	private JButton jButtonAccept;
	private MobilePlanSellAndBillSystem system;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				CreateAdditionalLineUI inst = new CreateAdditionalLineUI();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	public CreateAdditionalLineUI(){
		
	}
	public CreateAdditionalLineUI(MobilePlanSellAndBillSystem system) {
		super();
		initGUI();
		this.system = system;
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jTextFieldTitularLineNumber = new JTextField();
				getContentPane().add(jTextFieldTitularLineNumber);
				jTextFieldTitularLineNumber.setBounds(133, 47, 333, 28);
			}
			{
				jLabelTitularLineNumber = new JLabel();
				getContentPane().add(jLabelTitularLineNumber);
				jLabelTitularLineNumber.setText("Client DNI");
				jLabelTitularLineNumber.setBounds(12, 59, 62, 16);
			}
			{
				jTextFieldAdditionalLineNumber = new JTextField();
				getContentPane().add(jTextFieldAdditionalLineNumber);
				jTextFieldAdditionalLineNumber.setBounds(133, 87, 333, 28);
			}
			{
				jLabelAdditionalLineNumber = new JLabel();
				getContentPane().add(jLabelAdditionalLineNumber);
				jLabelAdditionalLineNumber.setText("Line Number");
				jLabelAdditionalLineNumber.setBounds(12, 99, 98, 16);
			}	
			{
				jTextFieldPlanNumber = new JTextField();
				getContentPane().add(jTextFieldPlanNumber);
				jTextFieldPlanNumber.setBounds(133, 127, 333, 28);
			}
			{
				jLabelPlanNumber = new JLabel();
				getContentPane().add(jLabelPlanNumber);
				jLabelPlanNumber.setText("Plan Number");
				jLabelPlanNumber.setBounds(12, 137, 103, 16);
			}	
			{

				jTextFieldAdditionalName = new JTextField();
				getContentPane().add(jTextFieldAdditionalName);
				jTextFieldAdditionalName.setBounds(133, 167, 333, 28);
			}
			{
				jLabelAdditionalName = new JLabel();
				getContentPane().add(jLabelAdditionalName);
				jLabelAdditionalName.setText("Additional Name");
				jLabelAdditionalName.setBounds(12, 172, 107, 16);
			}				
			{
				jButtonAccept = new JButton();
				getContentPane().add(jButtonAccept);
				jButtonAccept.setText("Create");
				jButtonAccept.setBounds(203, 283, 48, 23);

				jButtonAccept.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent evt) 
					{
						  try {
							system.createAdditionalLine(jTextFieldTitularLineNumber.getText(), 
									  jTextFieldAdditionalLineNumber.getText(), 									  
									  jTextFieldAdditionalName.getText(),
									  Integer.parseInt(jTextFieldPlanNumber.getText()));
						} catch (LineNotExistsException e) {
							ErrorReportView errorReportView = new ErrorReportView(e.getErrorMessage());
							errorReportView.setVisible(true);
						} catch (PlanNotExistsException e) {
							ErrorReportView errorReportView = new ErrorReportView(e.getErrorMessage());
							errorReportView.setVisible(true);
						} catch (LineAlreadyExistsException e) {
							ErrorReportView errorReportView = new ErrorReportView(e.getErrorMessage());
							errorReportView.setVisible(true);
						} catch (UserNotExistsException e) {
							ErrorReportView errorReportView = new ErrorReportView(e.getErrorMessage());
							errorReportView.setVisible(true);
						}
							
						  jTextFieldTitularLineNumber.setText("");
						  jTextFieldAdditionalLineNumber.setText("");
						  jTextFieldPlanNumber.setText("");
						  jTextFieldAdditionalName.setText("");	
					}
				});
				
			}//5383217
			/*
					this.dni = dni;
					this.domicilio = domicilio;
					this.email = email;
			 */
			pack();
			this.setSize(510, 417);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
